'use strict';

const Controller = require('egg').Controller;

class JuzhengController extends Controller {
  async index() {
   const ctx = this.ctx;
   let jz = new Array();
   let xh = new Array(23);
   for(let k=0;k<23;k++){   
    jz[k] = new Array(); 
    for(var j=0;j<23;j++){   
        jz[k][j]=1000;   
    }
   }

  
  for (let index = 0; index < 23; index++) {
    let cd = await ctx.service.nameses.find(index);
    xh[index]=cd.data[0]['nameOther'];
  }

  for (let index = 0; index < 23; index++) {
    let cd = await ctx.service.link.findto(xh[index]);
    for (let k = 0; k < cd.data.length; k++) {
      let zs;
      for (let f = 0; f < 23; f++) {
        if (xh[f] === cd.data[k]['nameOther']) {
          zs = f;
          break;
        }
      }
    jz[index][zs] = cd.data[k]['row'];
      
    }
  }
  for (let index = 0; index < 23; index++) {
    for (let fuc = 0; fuc < 23; fuc++) {
      if (index === fuc) {
        jz[index][fuc] = 0;
      }
      
    }
  }
  await ctx.service.linkClass.save(jz);
    
  }
}

module.exports = JuzhengController;
